// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
    {                                         \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    }
void err() { cerr << "\033[39;0m" << endl; }
template <typename T, typename... A>
void err(T a, A... x) {
    cerr << a << ' ';
    err(x...);
}
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 1e5 + 50;

int t, n;

int a[N];

pair<int, int> b[N];

int m;

int main(int argc, char const *argv[]) {
    // code
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    for (int i = 0, j; i < n; i = j + 1) {
        j = i;
        while (j + 1 < n && a[j + 1] == a[i])
            ++j;
        b[m++] = make_pair(i, j);
    }
    int ans = 0;
    for (int i = 0; i < m - 1; ++i)
        ans = max(ans, min(b[i].second - b[i].first + 1, b[i + 1].second - b[i + 1].first + 1));
    cout << ans * 2 << endl;
    return 0;
}
